package com.qhww.wechatmsg.mp.controller;

import com.qhww.wechatmsg.mp.entity.User;
import com.qhww.wechatmsg.mp.service.UserServiceImpl;
import com.qhww.wechatmsg.result.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author guoguo
 * @version 1.0
 * @description: TODO
 * @date 2022/8/31 09:53
 */
@RestController
@RequestMapping("user")
@Api(tags = "用户")
public class UserController {

    @Resource
    private UserServiceImpl userService;


    /**
     * 绑定用户(新增)
     * @param userInfo
     * @return
     */
    @PostMapping("bindUser")
    public R<User> bindUser(@RequestBody User userInfo){
        User sqlUser = userService.selectUserByOpenId(userInfo.getId());
        System.out.println(sqlUser);
        System.out.println(sqlUser);
        if(sqlUser ==null){
            userService.insertUser(userInfo);
        }
        return R.success(userService.selectUserByOpenId(userInfo.getId()));
    }

    /**
     * 查询用户 -重大项目用
     * @param phone
     * @return
     */
    @GetMapping("selectUserByPhone")
    public R<User> selectUserByPhone(@RequestParam(required = true) String phone){
        return  R.success(userService.selectUser(phone));
    }

    /**
     * 查询用户
     * @param openid
     * @return
     */
    @GetMapping("selectUserByOpenId")
    public R<User> selectUserByOpenId(@RequestParam(required = true) String openid){
        return  R.success(userService.selectUserByOpenId(openid));
    }
}
